package org.example.traing.persistence;


import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.traing.VO.CategoryVO;
import org.example.traing.VO.ClassVO;
import org.example.traing.VO.JobStatusVO;
import org.example.traing.VO.JobVO;
import org.example.traing.entity.JobDetail;
import org.example.traing.entity.UserDetail;
import org.example.traing.entity.UserJob;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Locale;

@Mapper
public interface JobMapper {

    @Select("select distinct class_Name from class_category")
    public List<ClassVO> getJobClass();

    @Select("select distinct category_Name from class_category")
    public List<CategoryVO> getJobCategory();

    @Select(" select distinct job_detail.job_id,job_name,job_address,job_address_detail,job_phone,job_descrption " +
            "from class_category , category_job ,job_detail " +
            "                where category_job.category_Name =#{category} and" +
            "                      class_category.category_Name=category_job.category_Name and" +
            "                      category_job.job_Id=job_detail.job_id")
    public List<JobDetail> getJob(String category);




    @Select("select * from job_detail where job_id=#{jobId}")
    public JobDetail getJobDetail(String jobId);

    @Select("select * from user_job,job_detail " +
            "where user_job.job_id=#{jobId} " +
            "and user_job.job_id=job_detail.job_id ")
    public List<JobStatusVO> getJobStatus(String jobId);


    @Insert("insert into category_job values (#{categoryName},#{jobId})")
    public int addCategoryJob (String categoryName,String jobId);

    @Insert("INSERT INTO job_detail " +
            "VALUES (#{jobId}, #{jobName}, #{jobAddress}, #{jobAddressDetail}," +
            "  #{jobMessage}, #{jobDescription}, #{jobPhone})")
    public int addJob(JobDetail jobDetail);

    @Select("select * from job_detail")
    public List<JobDetail> getAllJobs();

    @Select("select distinct category_Name from class_category where class_Name=#{className} ")
    public List<CategoryVO> getCategoryByClass(String className);


    @Update("UPDATE job_detail " +
            "SET " +
            "job_name = #{jobName}," +
            "job_address = #{jobAddress}," +
            "job_address_detail = #{jobAddressDetail}," +
            "job_message= #{jobMessage}," +
            "job_phone = #{jobPhone}," +
            "job_descrption= #{jobDescription} " +
            "WHERE " +
            "job_id = #{jobId}")
    public void updateJob(JobDetail jobDetail);



    @Select("select * FROM job_detail " +
            "WHERE job_detail.job_name LIKE CONCAT('%', #{keyword}, '%') " +
            "OR job_detail.job_descrption LIKE CONCAT('%', #{keyword}, '%')")
    public List<JobDetail> getKeyJobs(String keyword);

}
